<template>
  <ele-modal
    :width="950"
    :visible="visible"
    :confirm-loading="loading"
    :title="'统一赠送'"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    @ok="save"
  >
    <a-form
      :label-col="{ md: { span: 7 }, sm: { span: 4 }, xs: { span: 24 } }"
      :wrapper-col="{ md: { span: 17 }, sm: { span: 20 }, xs: { span: 24 } }"
    >
      <a-row :gutter="24">
        <a-col :md="12" :sm="12" :xs="12">
          <a-form-item label="赠送积分" v-bind="validateInfos.points_amount">
            <a-input
              placeholder="请输入"
              type="number"
              v-model:value="form.points_amount"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="12" :xs="12">
          <a-form-item label="有效期(天)" v-bind="validateInfos.points_valid">
            <a-input
              placeholder="请输入"
              type="number"
              v-model:value="form.points_valid"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="12" :xs="12">
          <a-form-item label="赠送礼金" v-bind="validateInfos.cash_amount">
            <a-input
              placeholder="请输入"
              type="number"
              v-model:value="form.cash_amount"
            />
          </a-form-item>
        </a-col>
        <a-col :md="12" :sm="12" :xs="12">
          <a-form-item label="有效期(天)" v-bind="validateInfos.cash_valid">
            <a-input
              placeholder="请输入"
              type="number"
              v-model:value="form.cash_valid"
            />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </ele-modal>
</template>

<script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { Form } from 'ant-design-vue';
  import { emailReg, phoneReg, identityReg } from 'ele-admin-pro';
  // 表格列配置
  const useForm = Form.useForm;
  const props = defineProps({
    // 弹窗是否打开
    visible: Boolean
  });
  const emit = defineEmits(['done', 'update:visible']);
  // 提交状态
  const loading = ref(false);
  // 表单数据
  const form = reactive({
    points_amount: '',
    points_valid: '',
    cash_amount: '',
    cash_valid: ''
  });
  // 表单验证规则
  const rules = reactive({
    points_amount: [
      {
        required: true,
        message: '请输入赠送积分',
        trigger: 'change'
      }
    ],
    points_valid: [
      {
        required: true,
        message: '请输入有限期',
        trigger: 'change'
      }
    ],
    cash_amount: [
      {
        required: true,
        message: '请输入赠送礼金',
        trigger: 'change'
      }
    ],
    cash_valid: [
      {
        required: true,
        message: '请输入有限期',
        trigger: 'change'
      }
    ]
  });

  const { validate, validateInfos } = useForm(form, rules);
  /* 保存编辑 */
  const save = () => {
    validate()
      .then(() => {
        emit('done', form);
      })
      .catch(() => {});
  };
  /* 更新visible */
  const updateVisible = (value) => {
    emit('update:visible', value);
  };
</script>
<style scoped></style>
